package com.springmvc.utils;

import org.apache.commons.lang3.ClassPathUtils;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;


public class XmlParser {

    public static String getBasePackage(String xml){
        //读取
        SAXReader saxReader = new SAXReader();
        InputStream inputStream = XmlParser.class.getClassLoader().getResourceAsStream(xml);

        try {
            Document doc = saxReader.read(inputStream);
            Element rootElement = doc.getRootElement();
            Element element = rootElement.element("component-scan");
            Attribute attribute = element.attribute("base-package");

            return attribute.getText();
        } catch (DocumentException e) {
            e.printStackTrace();
        }


        return "";
    }
}
